/*
 * @Author       : 邱狮杰
 * @Date         : 2021-08-31 11:37:05
 * @LastEditTime : 2021-09-10 09:43:25
 * @FilePath     : /newhope/src/main.ts
 * @Description  :
 *
 */
const ua = window.navigator.userAgent.toLocaleLowerCase();
const isIOS = /iphone|ipad|ipod/.test(ua);
const isAndroid = /android/.test(ua);
import { createApp } from "vue";
import "./main.css";
import { store } from "/@/store/index";
import { vueRouter } from "/@/router/index";
import Bus from "/@/utils/bus";
import App from "./App.vue";

const app = createApp(App);
function scrollAnimation(currentY: number, targetY: number) {
	// 获取当前位置方法
	// let currentY = document.documentElement.scrollTop || document.body.scrollTop;
	// 计算需要移动的距离
	let needScrollTop = targetY - currentY;
	let _currentY = currentY;
	setTimeout(() => {
		// 一次调用滑动帧数，每次调用会不一样
		let dist = Math.ceil(needScrollTop / 10);
		_currentY += dist;
		window.scrollTo(_currentY, currentY);
		// 如果移动幅度小于十个像素，直接移动，否则递归调用，实现动画效果
		if (needScrollTop > 10 || needScrollTop < -10) {
			scrollAnimation(_currentY, targetY);
		} else {
			window.scrollTo(_currentY, targetY);
		}
	}, 1);
}

//消息框失去焦点
document.querySelectorAll('textarea').forEach(item => {
	item.addEventListener('blur', () => {
		scrollToEnd();
	})
})
document.querySelectorAll('textarea').forEach(item => {
	item.addEventListener('focus', () => {
		scrollToEnd();
	})
})

function scrollToEnd() {
	document.body.scrollTo(document.body.clientHeight, 200);
}
// @ts-ignore
window.settimeout = 1000
app.config.globalProperties.$bus = new Bus();

app.use(vueRouter).use(store).mount("#app");
